@extends('layouts.app')

@section('title')
    失物模块
@endsection

@section('content')
    <div id="template">

        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    失物列表
                    <span style="float: right;">今天总共处理了 {{ $finish }} 条  总共有 {{ $losts->total() }} 条失物记录</span>
                </div>

                <div class="panel-body">

                    <form class="form-inline" action="{{ url('admin/modules/lost') }}" method="get" style="margin-bottom: 20px;">
                        <select name="publisher" class="form-control">
                            <option value="">全部发布者</option>
                            @foreach($publishers as $publisher)
                                <option value="{{ $publisher->publisher }}">{{ $publisher->user->name }}</option>
                            @endforeach
                        </select>
                        <select name="operatorId" class="form-control">
                            <option value="">全部处理者</option>
                            @foreach($operators as $operator)
                                <option value="{{ $operator->operator->id }}">{{ $operator->operator->name }}</option>
                            @endforeach
                        </select>
                        <select name="status" class="form-control">
                            <option value="">全部状态</option>
                            @foreach($statuses as $key => $status)
                                <option value="{{ $key }}">{{ $status }}</option>
                            @endforeach
                        </select>
                        <select name="role" class="form-control">
                            <option value="">全部角色</option>
                            @foreach($roles as $key => $role)
                                <option value="{{ $key }}">{{ $role }}</option>
                            @endforeach
                        </select>
                        <button type="submit" class="btn btn-primary">筛选</button>
                        <button type="button" class="btn btn-danger" id="clear">清除条件</button>
                    </form>
                    @if($losts->count() > 0)
                        <table class="table">
                            <thead>
                            <tr>
                                <th width="5%">id</th>
                                <td width="8%">失主</td>
                                <td width="5%">失主学号</td>
                                <td width="15%">失主班级</td>
                                <td width="15%">描述</td>
                                <td width="8%">发布者</td>
                                <td width="10%">发布者角色</td>
                                <td width="10%">膳管归还者</td>
                                <td width="5%">状态</td>
                                <td width="15%">创建时间</td>
                                <td width="10%"></td>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($losts as $lost)
                                <tr>
                                    <td>{{ $lost->id }}</td>
                                    <td>{{ $lost->name }}</td>
                                    <td>{{ $lost->number }}</td>
                                    <td>{{ $lost->class }}</td>
                                    <td>{{ $lost->description }}</td>
                                    <td>{{ $lost->user->name }}</td>
                                    <td>{{ $lost->roleText }}</td>
                                    <td>{{ $lost->operator ? $lost->operator->name : null }}</td>
                                    <td>
                                        @if($lost->status === 0)
                                            <button class="btn btn-warning btn-xs">{{ $lost->statusText }}</button>
                                        @elseif($lost->status === 1 && $lost->role === 1)
                                            <button class="btn btn-danger btn-xs">{{ $lost->statusText }}</button>
                                        @elseif($lost->status === 2)
                                            <button class="btn btn-success btn-xs">{{ $lost->statusText }}</button>
                                        @else
                                            <button class="btn btn-default btn-xs disabled">{{ $lost->statusText }}</button>
                                        @endif
                                    </td>
                                    <td>{{ $lost->created_at }}</td>
                                    <td>
                                        @if($lost->cover)
                                            <button class="btn btn-link" data-toggle="modal" data-target="#coverModal" onclick="setCover('{{ $lost->cover }}')">查看图片</button>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <div style="text-align: center;">
                            {{ $losts->appends(['operatorId' => $_GET['operatorId'] ?? null, 'status' => $_GET['status'] ?? null])->links() }}
                        </div>
                    @endif

                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="coverModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">失物图片</h4>
                </div>
                <div class="modal-body">
                    <img id="cover" src="" alt="" style="width: 100%;">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        $("select[name='operatorId']").val('{{ $_GET['operatorId'] ?? null }}');
        $("select[name='status']").val('{{ $_GET['status'] ?? null }}');
        $("select[name='role']").val('{{ $_GET['role'] ?? null }}');
        $("select[name='publisher']").val('{{ $_GET['publisher'] ?? null }}');

        $("#clear").click(function(){
            $("select").val(null);
        });

        function setCover(cover){
            $("#cover").attr('src', cover);
        }
    </script>
@endsection